import Vue from 'vue';
import Router from 'vue-router';
import Layout from '@/layout';
import { routerMode, publicPath } from '@/config/settings';

Vue.use(Router);

// 不需权限就可访问
export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true,
  },
  {
    path: '/register',
    component: () => import('@/views/register/index'),
    hidden: true,
  },
  {
    path: '/401',
    name: '401',
    component: () => import('@/views/401'),
    hidden: true,
  },
  {
    path: '/404',
    name: '404',
    component: () => import('@/views/404'),
    hidden: true,
  },
];

// 需要权限才能访问
export const asyncRoutes = [
  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [
      {
        path: 'dashboard',
        component: () => import('@/views/dashboard/index'),
        name: 'Dashboard',
        meta: {
          title: 'Dashboard',
          icon: 'dashboard',
          affix: true,
        },
      },
    ],
  },
  {
    path: '/festivalCalendar',
    component: Layout,
    redirect: '/festivalCalendar/index',
    children: [
      {
        path: 'index',
        component: () => import('@/views/festivalCalendar/index'),
        name: 'festivalCalendar',
        meta: {
          title: '节日问候',
          icon: 'festivalCalendar',
          affix: true,
        },
      },
    ],
  },
  {
    path: '/administrator',
    component: Layout,
    redirect: '/administrator/index',
    children: [
      {
        path: 'index',
        component: () => import('@/views/administrator/index'),
        name: 'Administrator',
        meta: {
          title: '管理员权限',
          icon: 'administrator',
          affix: true,
        },
      },
    ],
  },
  {
    path: '/organization',
    component: Layout,
    redirect: '/organization/index',
    children: [
      {
        path: 'index',
        component: () => import('@/views/organization/index'),
        name: 'organization',
        meta: {
          title: '组织架构',
          icon: 'organization',
          affix: true,
        },
      },
    ],
  },
  {
    path: '/staffInfo',
    component: Layout,
    redirect: '/staffInfo/index',
    children: [
      {
        path: 'index',
        component: () => import('@/views/staffInfo/index'),
        name: 'staffInfo',
        meta: { title: '人员信息查询', icon: 'staffInfo', affix: true },
      },
    ],
  },

  {
    path: '/invoiceInfo',
    component: Layout,
    redirect: '/invoiceInfo/index',
    children: [
      {
        path: 'index',
        component: () => import('@/views/invoiceInfo/index'),
        name: 'invoiceInfo',
        meta: { title: '企业开票信息', icon: 'invoiceInfo', affix: true },
      },
    ],
  },

  {
    path: '/thirdAuthorization',
    component: Layout,
    redirect: '/thirdAuthorization/index',
    children: [
      {
        path: 'index',
        component: () => import('@/views/thirdAuthorization/index'),
        name: 'thirdAuthorization',
        meta: { title: '授权绑定', icon: 'thirdAuthorization', affix: true },
      },
    ],
  },
  {
    path: '/birthdayParty',
    component: Layout,
    redirect: '/birthdayParty/index',
    children: [
      {
        path: 'index',
        component: () => import('@/views/birthdayParty/index'),
        name: 'birthdayParty',
        meta: { title: '生日会', icon: 'birthdayParty', affix: true },
      },
    ],
  },

  {
    path: '/noticeinformtion',
    component: Layout,
    redirect: '/noticeinformtion/index',
    children: [
      {
        path: 'index',
        component: () => import('@/views/noticeinformtion/index'),
        name: 'noticeinformtion',
        meta: { title: '公告资讯', icon: 'noticeinformtion', affix: true },
      },
    ],
  },
  {
    path: '/reconcilidetail',
    component: Layout,
    redirect: '/reconcilidetail/index',
    children: [
      {
        path: 'index',
        component: () => import('@/views/reconcilidetail/index'),
        name: 'reconcilidetail',
        meta: { title: '对账详情', icon: 'reconcilidetail', affix: true },
      },
      {
        path: 'checkReconcili',
        component: () => import('@/views/reconcilidetail/checkReconcili'),
        name: 'checkReconcili',
        meta: { title: '员工关联订单', icon: 'checkReconcili', affix: true },
      },
    ],
  },
  {
    path: '/careModule',
    component: Layout,
    redirect: '/careModule/index',
    children: [
      {
        path: 'index',
        component: () => import('@/views/careModule/index'),
        name: 'careModule',
        meta: { title: '关怀模块', icon: 'careModule', affix: true },
      },
    ],
  },
  {
    path: '/voteSignup',
    component: Layout,
    redirect: '/voteSignup/index',
    children: [
      {
        path: 'index',
        component: () => import('@/views/voteSignup/index'),
        name: 'voteSignup',
        meta: { title: '投票报名活动', icon: 'voteSignup', affix: true },
      },
    ],
  },
  {
    path: '/careCard',
    component: Layout,
    redirect: '/careCard/account',
    children: [
      {
        path: 'account',
        component: () => import('@/views/careCard/account'),
        name: 'careCardAccount',
        meta: { title: '福利管理', icon: 'careCardAccount', affix: true },
      },
      {
        path: 'distribute',
        component: () => import('@/views/careCard/distribute'),
        name: 'careCardDistribute',
        meta: { title: '福利发放', icon: 'careCardDistribute', affix: true },
      },
      {
        path: 'distributeDetail',
        component: () => import('@/views/careCard/distributeDetail'),
        name: 'distributeDetail',
        meta: { title: '分配详情', icon: 'careCardDistribute', affix: true },
      },
      {
        path: 'distributeHistory',
        component: () => import('@/views/careCard/distributeHistory'),
        name: 'distributeHistory',
        meta: { title: '发放记录', icon: 'distributeHistory', affix: true },
      },
      {
        path: 'distributeList',
        component: () => import('@/views/careCard/distributeList'),
        name: 'careCardDistributeList',
        meta: { title: '福利分配管理', icon: 'careCardDistributeList', affix: true },
      },
      {
        path: 'careCardReconciliation',
        component: () => import('@/views/careCard/careCardReconciliation/index'),
        name: 'careCardReconciliation',
        meta: { title: '企业对账', icon: 'careCardDistribute', affix: true },
      },
      {
        path: 'reconciliationDetail',
        component: () => import('@/views/careCard/reconciliationDetail/index'),
        name: 'reconciliationDetail',
        meta: { title: '企业对账详情', icon: 'reconciliationDetail', affix: true },
      },
      {
        path: 'relationOrder',
        component: () => import('@/views/careCard/relationOrder/index'),
        name: 'relationOrder',
        meta: { title: '关联订单', icon: 'relationOrder', affix: true },
      },
      {
        path: 'recoveryRecord',
        component: () => import('@/views/careCard/recoveryRecord/index'),
        name: 'recoveryRecord',
        meta: { title: '查看回收记录', icon: 'recoveryRecord', affix: true },
      },
      {
        path: 'paycollect',
        component: () => import('@/views/careCard/paycollect/index'),
        name: 'paycollect',
        meta: { title: '查看回款', icon: 'paycollect', affix: true },
      },
      {
        path: 'creditRecord',
        component: () => import('@/views/careCard/creditRecord/index'),
        name: 'creditRecord',
        meta: { title: '查看授信记录', icon: 'creditRecord', affix: true },
      },
    ],
  },
  {
    path: '/consumption',
    component: Layout,
    redirect: '/consumption/index',
    children: [
      {
        path: 'index',
        component: () => import('@/views/consumption/index'),
        name: 'consumption',
        meta: { title: '消费记录', icon: 'consumption', affix: true },
      },
    ],
  },
  {
    path: '/slGift',
    component: Layout,
    redirect: '/slGift/index',
    children: [
      {
        path: 'index',
        component: () => import('@/views/slGift/index'),
        name: 'slGift',
        meta: { title: '时令礼包', icon: 'slGift', affix: true },
      },
    ],
  },
  {
    path: '/jxGift',
    component: Layout,
    redirect: '/jxGift/index',
    children: [
      {
        path: 'index',
        component: () => import('@/views/jxGift/index'),
        name: 'jxGift',
        meta: { title: '精选福利礼包', icon: 'jxGift', affix: true },
      },
    ],
  },
  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true },
];

function createRouter() {
  return new Router({
    base: routerMode === 'history' ? publicPath : '',
    mode: routerMode,
    routes: [...constantRoutes, ...asyncRoutes],
  });
}

const router = createRouter();

export function resetRouter() {
  router.matcher = createRouter().matcher;
}

export default router;
